package com.airnewslinkosky.ticket.ui.personcenter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.airnewslinkosky.ticket.R;
import com.airnewslinkosky.ticket.ui.BaseActivity;
import com.airnewslinkosky.ticket.ui.PersonCenter;
import com.mobclick.android.MobclickAgent;

public class CompanyList   extends BaseActivity implements OnClickListener,AdapterView.OnItemClickListener{
	private Button backBut;
	public SimpleAdapter sa;
	public ListView lv;
	private SharedPreferences sp;
	
	List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.company_list);
		
		activityList.add(this); 
		
		sp = getSharedPreferences("UserInfoB2B", Context.MODE_WORLD_WRITEABLE | Context.MODE_WORLD_READABLE);
		
		backBut = (Button) findViewById(R.id.backBut);
		backBut.setOnClickListener(this);
		
		lv = (ListView) findViewById(R.id.companyList);
		lv.setOnItemClickListener(this);
		
		
		renderData();
		
	}
	
	private void renderData() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("clientNo", "2132323");
		map.put("clientName", "联东伟业");
		map.put("contactName", "周科");
		map.put("mobile", "13643456789");
		map.put("address", "广州大道南138号一栋602室");
		
		data.add(map);
		
		 map = new HashMap<String, Object>();
		map.put("clientNo", "G43333");
		map.put("clientName", "华为电子");
		map.put("contactName", "李从");
		map.put("mobile", "13643456789");
		map.put("address", "广州天河华景新城23号234室");
		
		data.add(map);
		
		sa = new SimpleAdapter(this, data, R.layout.company_row, new String[] {
				"clientNo", "clientName", "contactName", "mobile", "address"},
				new int[] { R.id.clientNo, R.id.clientName, R.id.contactName,
						R.id.mobile, R.id.address});
		lv.setAdapter(sa);  
		sa.notifyDataSetChanged();
	}
	
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.backBut: 
			Intent intentR = new Intent();
			intentR.setClass(CompanyList.this, PersonCenter.class);
			startActivity(intentR);
			break;
	}
	}
	
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		Map<String, Object> item = (Map<String, Object>) lv.getAdapter().getItem(position);
//		OrderInfo orderInfo = (OrderInfo)item.get("orderInfo");
		
		Intent intent = new Intent();
		
		intent.setClass(this, CompanyEdit.class);
		
		startActivity(intent);
	}

	
	public void onResume() {     
		super.onResume();     
		MobclickAgent.onResume(this); 
	}  
	
	public void onPause() {     
		super.onPause();     
		MobclickAgent.onPause(this); 
	}  
}
